package com.glodon.paas.monitor.server.biz.service.impl;

import java.util.ArrayList;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.glodon.paas.monitor.server.biz.domain.MonitorApplicationEntity;
import com.glodon.paas.monitor.server.biz.mapper.MonitorApplicationMapper;
import com.glodon.paas.monitor.server.biz.service.MonitorApplicationService;
import com.glodon.paas.monitor.server.exception.MonitorException;

@Service("monitorApplicationService")
public class MonitorApplicationServiceImpl implements MonitorApplicationService {

	@Autowired
	private MonitorApplicationMapper	monitorApplicationMapper;

	@Override
	public int deleteByPrimaryKey(Long id) throws MonitorException {
		if (null == id) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"deleteByPrimaryKey application id is null!");
		}
		return monitorApplicationMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(MonitorApplicationEntity record) throws MonitorException {
		if (null == record || StringUtils.isBlank(record.getAppName())) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID, "insert application record is null!");
		}
		return monitorApplicationMapper.insert(record);
	}

	@Override
	public int insertSelective(MonitorApplicationEntity record) throws MonitorException {
		if (null == record || StringUtils.isBlank(record.getAppName())) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"insertSelective application record is null!");
		}
		int size = monitorApplicationMapper.insertSelective(record);
		return size;
	}

	@Override
	public MonitorApplicationEntity selectByPrimaryKey(Long id) throws MonitorException {
		if (null == id) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"selectByPrimaryKey application id is null!");
		}
		return monitorApplicationMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(MonitorApplicationEntity record) throws MonitorException {
		if (null == record || null == record.getId()) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"updateByPrimaryKeySelective application record is null!");
		}
		return monitorApplicationMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(MonitorApplicationEntity record) throws MonitorException {
		if (null == record || null == record.getId()) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"updateByPrimaryKey application record is null!");
		}
		return monitorApplicationMapper.updateByPrimaryKey(record);
	}

	@Override
	public MonitorApplicationEntity selectByAppName(String appName) throws MonitorException {
		if (null == appName) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"updateByPrimaryKey application appName is null!");
		}
		return monitorApplicationMapper.selectByAppName(appName);
	}

	@Override
	public ArrayList<MonitorApplicationEntity> queryMonitorApplication(MonitorApplicationEntity record)
			throws MonitorException {

		return monitorApplicationMapper.queryMonitorApplication(record);
	}

}
